let usernameInput = $('input[name="username"]')
let passwordInput = $('input[name="password"]')
$('button[name="register"]').on('click', function () {
    let username = usernameInput.val()
    let password = passwordInput.val()
    // 正则表达式
    let reg = /\S/
    if (reg.test(username) == false || reg.test(password) == false) {
        alert("用户名或密码不能为空")
        return
    }
    let userStr = {
        username,
        password
    }
    let data = JSON.parse(localStorage.getItem('userList')) || []
    let newData = data.find((item) => item.username == userStr.username)
    if (newData) {
        alert("用户已存在")
        return
    } else {
        data.push(userStr)
        localStorage.setItem('userList', JSON.stringify(data))
        alert("注册成功")
    }
})